<script setup>
import TestCom from '@/components/test-com.vue'
import {onMounted, ref} from 'vue'

// 通过一个ref绑定元素
const inp = ref(null)

// 生命周期钩子 onMount
onMounted(()=> {
    // console.log(inp.value);
    // inp.value.focus()  
})

const clickFn = () => {
 console.log(inp.value);
    inp.value.focus()  
}

const testRef = ref(null)
const getCom = () => {
  console.log(testRef.value);
}
</script>

<template>
    <div>
        <input ref="inp" type="text">
        <button @click="clickFn">点击让输入框聚焦</button>
    </div>
    <TestCom ref="testRef"></TestCom>
    <button @click="getCom">获取组件</button>
</template>